package com.huaxin.common.view;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.BottomSheetDialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.huaxin.common.R;
import com.huaxin.common.tools.Log;
import com.huaxin.common.view.wheelview.adapters.ArrayWheelAdapter;
import com.huaxin.common.view.wheelview.views.OnWheelChangedListener;
import com.huaxin.common.view.wheelview.views.WheelView;

/**
 * Created by Administrator on 2016/10/20.
 */
public class SelectDialog extends BottomSheetDialogFragment implements View.OnClickListener {
    private View mView;
    private WheelView wheelview;
    private ArrayWheelAdapter adapter;
    private  int currentPosition;
    private String[] array;
    private TextView ok;
    private TextView cancle;
    private boolean okFlag = false;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.dialog_select,container,false);
        wheelview =  (WheelView)mView.findViewById(R.id.wheelview);
        adapter = new ArrayWheelAdapter<String>(getContext(),array);
        wheelview.setViewAdapter(adapter);
        Log.d("Zoes", "theme" +getTheme());
        wheelview.addChangingListener(new OnWheelChangedListener() {
            @Override
            public void onChanged(WheelView wheel, int oldValue, int newValue) {
                Log.d("Zoes", "oldValue" + oldValue + "newValue" + newValue);
                currentPosition = newValue;
            }
        });
        ok = (TextView)mView.findViewById(R.id.ok);
        cancle = (TextView)mView.findViewById(R.id.cancel);
        ok.setOnClickListener(this);
        cancle.setOnClickListener(this);
        return mView;
    }

    public void setArray(String[] array) {
        this.array = array;
    }

    public int getCurrentPosition() {
        return currentPosition;
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.cancel) {
            okFlag = false;
            dismiss();

        } else if (i == R.id.ok) {
            okFlag = true;
            dismiss();

        }
    }
}
